package com.karson.front.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.karson.common.exception.ExceptionCodeEnum;
import com.karson.common.request.AlbumSearchRequest;
import com.karson.common.request.PageParamRequest;
import com.karson.common.request.UserActionRequest;
import com.karson.common.response.AlbumResponse;
import com.karson.common.response.AlbumTrackResponse;
import com.karson.common.response.CommonResult;
import com.karson.service.dao.AlbumAuthorMapper;
import com.karson.service.dao.AlbumTagsMapper;
import com.karson.service.service.AlbumInfoService;
import com.karson.service.service.UserActionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZKS
 */
@RestController
@RequestMapping("/api/album")
@Tag(name = "专辑管理接口")
public class AlbumController {
    @Autowired
    private AlbumInfoService albumInfoService;

    @Operation(summary = "分页列表")
    @PostMapping("/list")
    public CommonResult<IPage<AlbumResponse>> getList(@RequestBody @Validated @ParameterObject AlbumSearchRequest albumSearchRequest) {
        IPage<AlbumResponse> albumResponseIPage = new Page<>(albumSearchRequest.getCurrent(), albumSearchRequest.getSize());
        IPage<AlbumResponse> userCommonPage =  albumInfoService.pageList(albumResponseIPage,albumSearchRequest);
        return CommonResult.success(userCommonPage);
    }
    @Operation(summary = "获取专辑详情")
    @GetMapping("/getAlbumDetail/{albumId}")
    public CommonResult<AlbumResponse> getDetail(@PathVariable("albumId") Integer albumId) {
        if (albumId != null && albumId <= 0) {
            return CommonResult.failed(ExceptionCodeEnum.VALIDATE_FAILED);
        }
        AlbumResponse albumResponse = albumInfoService.getAllAlbumById(albumId);
        return CommonResult.success(albumResponse);
    }
    @Operation(summary = "获取专辑歌曲信息")
    @GetMapping("/getAlbumTrack/{albumId}")
    public CommonResult<AlbumTrackResponse> getAlbumTrack(@PathVariable("albumId") Integer albumId) {
        if (albumId != null && albumId <= 0) {
            return CommonResult.failed(ExceptionCodeEnum.VALIDATE_FAILED);
        }
        AlbumTrackResponse albumTrackResponse = albumInfoService.getAlbumTrackById(albumId);
        return CommonResult.success(albumTrackResponse);
    }
}
